﻿using System;
using System.Threading;
using System.Windows.Forms;
using GeneratorModels.Forms;
using GeneratorModels.Utility;

namespace GeneratorModels
{
    internal static class Program
    {
        /// <summary>
        ///     应用程序的主入口点。
        /// </summary>
        [STAThread]
        private static void Main()
        {
            bool isRuned;
            var mutex = new Mutex(true, "GeneratorModels", out isRuned);
            if (isRuned)
            {
                Application.ThreadException += Application_ThreadException; //UI线程异常
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //多线程异常
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form_Main());
                mutex.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("程序已启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Log.ErrorFormat("【CurrentDomain_UnhandledException】sender：{0}，ex：{1}", sender, e.ExceptionObject);
        }

        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            Log.ErrorFormat("【Application_ThreadException】sender：{0}，ex：{1}", sender, e.Exception);
        }
    }
}